package com.atguigu.atcrowdfunding.potal.listener;

import com.atguigu.atcrowdfunding.bean.Member;
import com.atguigu.atcrowdfunding.potal.service.MemberService;
import com.atguigu.atcrowdfunding.potal.service.TicketService;
import com.atguigu.atcrowdfunding.util.ApplicationContextUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.context.ApplicationContext;

/**
 * @author xzt
 * @create 2021-03-13 14:43
 */
public class RefuseListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        Integer memberid = (Integer) delegateExecution.getVariable("memberid");

        //先获取ioc容器
        ApplicationContext applicationContext = ApplicationContextUtils.applicationContext;

        //获取TicketService 和MemberService对象
        TicketService ticketService = applicationContext.getBean(TicketService.class);
        MemberService memberService = applicationContext.getBean(MemberService.class);

        //更新t_member表的authstatus字段 -》已实名认证
        Member member = memberService.getMemberById(memberid);
        member.setAuthstatus("0");
        memberService.updateAuthstatus(member);

        memberService.deleteImg(member);

        //更新t_ticket表的status字段 1 -> 表示流程结束
        ticketService.updateStatus(member);
    }

}
